/*
 * Created by Gibbs on 2021/1/1.
 * Copyright (c) 2021 Gibbs. All rights reserved.
 */

#ifndef GPLAYER_FRAMESOURCE_H
#define GPLAYER_FRAMESOURCE_H


#include "media/MediaData.h"
#include "ConcurrentQueue.h"

extern "C" {
#include <demuxing/avformat_def.h>
}

class FrameSource {

public:
    FrameSource(int audioMaxSize, int audioMixSize, int videoMaxSize, int videoMinSize);

    ~FrameSource();

public:
    unsigned long pushAudFrame(MediaData *frame);

    unsigned long pushVidFrame(MediaData *frame);

    unsigned long readAudFrame(MediaData **frame);

    unsigned long readVidFrame(MediaData **frame);

    void popAudFrame(MediaData *frame);

    void popVidFrame(MediaData *frame);

    void flush();

    void quit();

    unsigned long audioSize();

    unsigned long videoSize();

    void setEof() {
        isEof = true;
    }

    void setStreams(bool audio, bool video) {
        hasVideo = video;
        hasAudio = audio;
    }

    bool containAudio() {
        return hasAudio;
    }

    bool containVideo() {
        return hasVideo;
    }

private:
    ConcurrentQueue<MediaData *> *audioFrameQueue;
    ConcurrentQueue<MediaData *> *videoFrameQueue;
    int audioMaxSize;
    int audioMinSize;
    int videoMaxSize;
    int videoMinSize;
    bool isEof;
    bool hasVideo;
    bool hasAudio;
};


#endif //GPLAYER_FRAMESOURCE_H
